﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using TouchRC.Logic;
using Microsoft.Drawing;

namespace TouchRC.Classes
{
    public enum MenuTypes
    {
        NowPlaying,
        Music,
        TvDvd,
        Video,
        Picture
    }

    public enum MenuItemOption
    { 
        NowPlaying,
        MusicQueue,
        MusicLibrary,
        TvLive,
        TvGuide,
        TvRecorded,
        DVD,
        VideoLibrary,
        PictureLibrary
    }

    public class MainMenuItem
    {
        private MenuTypes m_MenuType;
        private List<MainMenuOption> m_MenuOptions;
        private string m_Title = string.Empty;

        public MainMenuItem(MenuTypes menuType)
        {
            m_MenuType = menuType;
            m_MenuOptions = MenuFactory.GetMenuOptions(menuType);
            m_Title = GetTitle(menuType);
        }

        private string GetTitle(MenuTypes menuType)
        {
            switch (menuType)
            {
                case MenuTypes.Music:
                    return "My Music";
                case MenuTypes.NowPlaying:
                    return "Now Playing";
                case MenuTypes.Picture:
                    return "My Pictures";
                case MenuTypes.TvDvd:
                    return "TV & DVD";
                case MenuTypes.Video:
                    return "My Videos";
                default:
                    throw new InvalidCastException("Not implemented that yet!! menu type : " + menuType.ToString());
            }
        }

        public string Title { get { return m_Title; } }

        public List<MainMenuOption> Options { get { return m_MenuOptions; } }
    }

    public static class MenuFactory
    {
        internal static List<MainMenuOption> GetMenuOptions(MenuTypes type)
        {
            switch (type)
            {
                case MenuTypes.NowPlaying:
                    {
                        return GetNowPlaying();
                    }
                case MenuTypes.Music:
                    {
                        return GetMusic();
                    }
                case MenuTypes.Picture:
                    {
                        return GetPictures();
                    }
                case MenuTypes.TvDvd:
                    {
                        return GetTvDVD();
                    }
                case MenuTypes.Video:
                    {
                        return GetVideo();
                    }
                default:
                    throw new NotImplementedException("Not implemented yet.");
            }
            return new List<MainMenuOption>();
        }

        private static List<MainMenuOption> GetVideo()
        {
            MainMenuOption library = new MainMenuOption();

            library.Image = ImageFactory.GetMenuOptionImage(MenuItemOption.VideoLibrary);
            library.Option = MenuItemOption.VideoLibrary;

            return new List<MainMenuOption> { library };
        }

        private static List<MainMenuOption> GetTvDVD()
        {
            List<MainMenuOption> list = new List<MainMenuOption>(); 
            MainMenuOption option = new MainMenuOption();
            option.Image = ImageFactory.GetMenuOptionImage(MenuItemOption.TvLive);
            option.Option = MenuItemOption.TvLive;
            list.Add(option);

            //option = new MainMenuOption();
            //option.Image = ImageFactory.GetMenuOptionImage(MenuItemOption.TvGuide);
            //option.Option = MenuItemOption.TvGuide;
            //list.Add(option);

            //option = new MainMenuOption();
            //option.Image = ImageFactory.GetMenuOptionImage(MenuItemOption.TvRecorded);
            //option.Option = MenuItemOption.TvRecorded;
            //list.Add(option);

            option = new MainMenuOption();
            option.Image = ImageFactory.GetMenuOptionImage(MenuItemOption.DVD);
            option.Option = MenuItemOption.DVD;
            list.Add(option);

            return list; // new List<MainMenuOption> { option }; ;
        }

        private static List<MainMenuOption> GetPictures()
        {
            MainMenuOption option = new MainMenuOption();

            option.Image = ImageFactory.GetMenuOptionImage(MenuItemOption.PictureLibrary);
            option.Option = MenuItemOption.PictureLibrary;

            return new List<MainMenuOption> { option };
        }

        private static List<MainMenuOption> GetMusic()
        {
            MainMenuOption library = new MainMenuOption();
            library.Image = ImageFactory.GetMenuOptionImage(MenuItemOption.MusicLibrary);
            library.Option = MenuItemOption.MusicLibrary;

            MainMenuOption queue = new MainMenuOption();
            queue.Image = ImageFactory.GetMenuOptionImage(MenuItemOption.MusicQueue);
            queue.Option = MenuItemOption.MusicQueue;

            return new List<MainMenuOption> { library, queue };
        }

        private static List<MainMenuOption> GetNowPlaying()
        {
            MainMenuOption option = new MainMenuOption();
            option.Image = ImageFactory.GetMenuOptionImage(MenuItemOption.NowPlaying);
            option.Option = MenuItemOption.NowPlaying;

            return new List<MainMenuOption> { option };
        }

        public static List<MainMenuItem> GetMenuItems()
        {
            List<MainMenuItem> options = new List<MainMenuItem>();

            MainMenuItem nowPlaying = new MainMenuItem(MenuTypes.NowPlaying);
            MainMenuItem music = new MainMenuItem(MenuTypes.Music);
            MainMenuItem tvDvd = new MainMenuItem(MenuTypes.TvDvd);
            MainMenuItem video = new MainMenuItem(MenuTypes.Video);
            MainMenuItem pictures = new MainMenuItem(MenuTypes.Picture);

            options.Add(nowPlaying);
            options.Add(music);
            options.Add(tvDvd);
            options.Add(video);
            options.Add(pictures);

            return options;
        }
    }

    public class MainMenuOption
    {
        public IImage Image { get; set; }
        public MenuItemOption Option { get; set; }
    }
}
